#ifndef _TAROT_TAROTSTAR_H
#define _TAROT_TAROTSTAR_H


#include "../Main.h"
#include "CardSet.h"
#include "Card.h"
#include "TarotDeck.h"


class TarotStar : public CardSet {
private:
	static const char EDW[16];

	struct star_card {
		char *name;
		char *title;
		int x;							/**< X location of card. */
		int y;							/**< Y location of card. */
		int width;						/**< Width of card. */
		int height;						/**< Height of card. */
		int grid_x;						/**< X location of card relative to grid. */
		int grid_y;						/**< X location of card relative to grid. */
		int state;
		int edw;							/**< Elemental Dignities. */
	};

	TarotDeck *deck;					/**< Tarot deck used for this star. */
//	int grid;							/**< Size of grid. */
	star_card *star;					/**< Information about the cardpositions in the star. */
	struct {
		int card_width;
		int card_height;
		int width;
		int height;
	} grid;
	int picked;							/**< Number of cards picked. */
	int edmin;							/**< Elemental Dignities minimum value. */
	int edmax;							/**< Elemental Dignities maximum value. */
	int edsum;							/**< Elemental Dignities sum. */
	int elements[4];					/**< Elements. */
	char types[3];						/**<  */
	char groups[14];					/**<  */

	FILE *openFile(const char *fn);
	void readHeader(FILE *fp);
	void readCards(FILE *fp);

public:
	static int edWeight(int e1) { return EDW[(1<<e1)]; }
	static int edWeight(int e1,int e2) { return EDW[(1<<e1)|(1<<e2)]; }
	static int edWeight(int e1,int e2,int e3) { return EDW[(1<<e1)|(1<<e2)|(1<<e3)]; }
	static int edWeight(int e1,int e2,int e3,int e4) { return EDW[(1<<e1)|(1<<e2)|(1<<e3)|(1<<e4)]; }

	TarotStar(TarotDeck &d);
	~TarotStar();

	void paint(cairo_t *cr,GdkRectangle *rects=0,int nrects=0);

	int getStarWidth();
	int getStarHeight();

	void setDeck(TarotDeck &d) { deck = &d; }
	void placeCards(GdkRectangle &r);
	void getBounds(int i,GdkRectangle &r);
	int findCardIndex(int x,int y);
	bool contains(int i,int x,int y);
	bool intersects(int i,GdkRectangle &r);

	const char *getCardName(int i) { return star && i<sz? star[i].name : ""; }
	const char *getCardTitle(int i) { return star && i<sz? star[i].title : ""; }

	void pickCard(Card &c,int i=-1);
	bool isFull() { return picked==sz; }

	void analyze();
	int ed(int n) { return star[n].edw; }
	int edMin() { return edmin; }
	int edMax() { return edmax; }
	int edSum() { return edsum; }
	int getElement(int e) { return elements[e]; }
	int getType(int t) { return types[t]; }
	int getGroup(int g) { return groups[g-1]; }
};



#endif /* _TAROT_TAROTSTAR_H */


